#import "GameTypes.h"

@implementation Position

- (instancetype)initWithRow:(NSInteger)row column:(NSInteger)column {
    self = [super init];
    if (self) {
        _row = row;
        _column = column;
    }
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    return [[Position alloc] initWithRow:self.row column:self.column];
}

- (BOOL)isEqual:(id)object {
    if (self == object) return YES;
    if (![object isKindOfClass:[Position class]]) return NO;
    
    Position *other = (Position *)object;
    return self.row == other.row && self.column == other.column;
}

- (NSUInteger)hash {
    return self.row * 10 + self.column;
}

@end

@implementation GridItem

- (instancetype)initWithType:(GridType)type value:(NSInteger)value position:(Position *)position {
    self = [super init];
    if (self) {
        _type = type;
        _value = value;
        _position = position;
        _isRevealed = YES;
    }
    return self;
}

- (NSString *)description {
    NSDictionary *typeNames = @{
        @(GridTypeEmpty): @"Empty",
        @(GridTypeWeapon): @"Weapon",
        @(GridTypeHealthPotion): @"HealthPotion",
        @(GridTypeEnemy): @"Enemy",
        @(GridTypeBoss): @"Boss",
        @(GridTypePlayer): @"Player"
    };
    return [NSString stringWithFormat:@"%@(%ld)@(%ld,%ld)", 
            typeNames[@(self.type)], (long)self.value, 
            (long)self.position.row, (long)self.position.column];
}

@end